<template>
  <div>
    <router-link to="/layout/mid1">mid1</router-link>
    <router-link to="/layout/mid2">mid2</router-link>
    <router-link to="/layout">mid3</router-link>
    <!-- 上方不会变的组件 -->
    <Vtop></Vtop>
    <!-- 左侧不会变的组件 -->
    <Vleft></Vleft>
    <!-- 中间会变的组件 -->
    <router-view></router-view>
    <hr />
    <!-- 动态组件的另一种方式：is属性 -->
    <button @click="toggle">toggle</button>
    <transition
      enter-active-class="animate__animated animate__backOutUp"
      leave-active-class="animate__animated animate__backInDown"
    >
      <!-- 使用transition组件包裹着会变的组件，以此来增加过渡效果 -->
      <div :is="comName"></div>
    </transition>
    <transition name="aaa">
      <div :is="comName"></div>
    </transition>
    <router-link to="/layout/mid1">mid1</router-link>
    <router-link to="/layout/mid2">mid2</router-link>
    <router-link to="/layout">mid3</router-link>
    <router-link to="/404">404</router-link>
  </div>
</template>

<script>
import Vtop from "../components/Vtop.vue";
import Vleft from "../components/Vleft.vue";
// 引入css的效果 不需要注册
import "animate.css";
export default {
  data() {
    return {
      comName: Vtop,
    };
  },
  components: {
    Vtop,
    Vleft,
  },
  methods: {
    toggle() {
      this.comName === "Vtop"
        ? (this.comName = "Vleft")
        : (this.comName = "Vtop");
    },
  },
};
</script>

<style>
.aaa-enter {
  opacity: 0;
}
.aaa-enter-active {
  transition: all 2s;
}
.aaa-enter-to {
  opacity: 1;
}
.aaa-leave {
  opacity: 1;
}
.aaa-leave-active {
  transition: all 2s;
}
.aaa-leave-to {
  opacity: 0;
}
</style>